package com.tt.fashionWebSite.controller;

import com.tt.fashionWebSite.dto.*;
import com.tt.fashionWebSite.service.Ad_PostService;
import com.tt.fashionWebSite.service.Ad_ProductDetailService;
import com.tt.fashionWebSite.service.Ad_ProductService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.servlet.ModelAndView;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import java.io.IOException;
import java.text.ParseException;
import java.util.List;
import java.util.Map;

@Controller
public class Ad_ProductDetailController {
    @Autowired
    private Ad_ProductDetailService ad_productDetailService;

    @SuppressWarnings("rawtypes")
    @RequestMapping(value = "/admin/ad_GetAllProductDetail", method = RequestMethod.GET)
    public @ResponseBody
    JsonResponseDto<List<ChiTietSanPhamDto>> getAllProductDetail(HttpServletRequest request) {
        return new JsonResponseDto<List<ChiTietSanPhamDto>>(ad_productDetailService.getAllProductDetail(), JsonResponseCode.SUCCESS);
    }

    @SuppressWarnings("rawtypes")
    @RequestMapping(value = "/admin/getAllProductDetailInPicture", method = RequestMethod.GET)
    public @ResponseBody
    JsonResponseDto<List<ChiTietSanPhamDto>> getAllProductDetailInPicture(HttpServletRequest request) {
        return new JsonResponseDto<List<ChiTietSanPhamDto>>(ad_productDetailService.getAllProductDetail(), JsonResponseCode.SUCCESS);
    }

    @SuppressWarnings("rawtypes")
    @RequestMapping(value = "/admin/ad_GetAllProductList", method = RequestMethod.GET)
    public @ResponseBody
    JsonResponseDto<List<LoaiDanhMucSanPhamDto>> getAllProductList(HttpServletRequest request) {
        return new JsonResponseDto<List<LoaiDanhMucSanPhamDto>>(ad_productDetailService.getAllProductList(), JsonResponseCode.SUCCESS);
    }

    @SuppressWarnings("rawtypes")
    @RequestMapping(value = "/admin/ad_GetAllColor", method = RequestMethod.GET)
    public @ResponseBody
    JsonResponseDto<List<MauSacDto>> getAllColor(HttpServletRequest request) {
        return new JsonResponseDto<List<MauSacDto>>(ad_productDetailService.getAllColor(), JsonResponseCode.SUCCESS);
    }

    @SuppressWarnings("rawtypes")
    @RequestMapping(value = "/admin/ad_GetAllSize", method = RequestMethod.GET)
    public @ResponseBody
    JsonResponseDto<List<KichThuocDto>> getAllSize(HttpServletRequest request) {
        return new JsonResponseDto<List<KichThuocDto>>(ad_productDetailService.getAllSize(), JsonResponseCode.SUCCESS);
    }

    @SuppressWarnings("rawtypes")
    @RequestMapping(value = "/admin/ad_GetAllMotifInProductDetail", method = RequestMethod.GET)
    public @ResponseBody
    JsonResponseDto<List<HoaTietDto>> getAllMotif(HttpServletRequest request) {
        return new JsonResponseDto<List<HoaTietDto>>(ad_productDetailService.getAllMotif(), JsonResponseCode.SUCCESS);
    }

    @SuppressWarnings("rawtypes")
    @RequestMapping(value = "/admin/ad_GetAllProductInProductDetail", method = RequestMethod.GET)
    public @ResponseBody
    JsonResponseDto<List<SanPhamDto>> getAllProduct(HttpServletRequest request) {
        return new JsonResponseDto<List<SanPhamDto>>(ad_productDetailService.getAllProduct(), JsonResponseCode.SUCCESS);
    }

    @SuppressWarnings("rawtypes")
    @RequestMapping(value = "/admin/ad_AddProductDetail", method = RequestMethod.POST)
    public @ResponseBody
    JsonResponseDto<Integer> addProductDetail(HttpServletRequest request, @RequestBody ChiTietSanPhamDto productDetailDto) {
        return new JsonResponseDto<Integer>(ad_productDetailService.addProductDetail(productDetailDto));
    }

    @SuppressWarnings("rawtypes")
    @RequestMapping(value = "/admin/getDataDetailOfDataCommon/{maSP}", method = RequestMethod.GET)
    public @ResponseBody
    JsonResponseDto<SanPhamFullDto> getDataDetailOfDataCommon(HttpServletRequest request, @PathVariable String maSP) throws ServletException, IOException {
        return new JsonResponseDto<SanPhamFullDto>(ad_productDetailService.getDataDetailOfDataCommon(maSP), JsonResponseCode.SUCCESS);
    }

    @SuppressWarnings("rawtypes")
    @RequestMapping(value = "/admin/getDataDetailForDeal/{color}/{motif}/{size}", method = RequestMethod.GET)
    public @ResponseBody
    JsonResponseDto<SanPhamFullDto> getDataDetailForDeal(HttpServletRequest request, @PathVariable String color, @PathVariable String motif, @PathVariable String size) throws ServletException, IOException {
        return new JsonResponseDto<SanPhamFullDto>(ad_productDetailService.getDataDetailForDeal(color,motif,size), JsonResponseCode.SUCCESS);
    }

    @SuppressWarnings("rawtypes")
    @RequestMapping(value = "/admin/toProductInformationPage/{maSP}", method = RequestMethod.GET)
    public @ResponseBody
    ModelAndView toProductInformationPage(HttpServletRequest request, @PathVariable String maSP, Map<String, Object> map) throws ParseException {
        map.put("maSP", maSP);
        return new ModelAndView("admin/ad-product-detail-add");
    }

    @SuppressWarnings("rawtypes")
    @RequestMapping(value = "/admin/toProductCommonPage", method = RequestMethod.GET)
    public @ResponseBody
    ModelAndView toProductCommonPage(HttpServletRequest request, @PathVariable String maSP, Map<String, Object> map) throws ParseException {
        return new ModelAndView("admin/ad-product-common");
    }

    @SuppressWarnings("rawtypes")
    @RequestMapping(value = "/admin/toEditProductDetailPage/{maCTSP}", method = RequestMethod.GET)
    public @ResponseBody
    ModelAndView toEditProductDetailPage(HttpServletRequest request, @PathVariable String maCTSP, Map<String, Object> map) throws ParseException {
        map.put("maCTSP", maCTSP);
        return new ModelAndView("admin/ad-product-detail-edit");
    }

    @SuppressWarnings("rawtypes")
    @RequestMapping(value = "/admin/getInformationOfProductDetail", method = RequestMethod.POST)
    public @ResponseBody
    JsonResponseDto<ChiTietSanPhamDto> getInformationOfProductDetail(HttpServletRequest request, @RequestBody ChiTietSanPhamDto productDto) {
        return new JsonResponseDto<ChiTietSanPhamDto>(ad_productDetailService.getInformationOfProductDetail(productDto), JsonResponseCode.SUCCESS);
    }

    @SuppressWarnings("rawtypes")
    @RequestMapping(value = "/admin/ad_UpdateProductDetail", method = RequestMethod.POST)
    public @ResponseBody
    JsonResponseDto<ChiTietSanPhamDto> updateProductDetail(HttpServletRequest request, @RequestBody ChiTietSanPhamDto productDto) {
        return new JsonResponseDto<ChiTietSanPhamDto>(ad_productDetailService.updateProductDetail(productDto), JsonResponseCode.SUCCESS);
    }

    @SuppressWarnings("rawtypes")
    @RequestMapping(value = "/admin/deleteProductDetail/", method = RequestMethod.POST)
    public @ResponseBody
    JsonResponseDto<Integer> deleteProductDetail(HttpServletRequest request, @RequestBody List<ChiTietSanPhamDto> chiTietSanPhamDtos) {
        return new JsonResponseDto<Integer>(ad_productDetailService.deleteProductDetail(chiTietSanPhamDtos));
    }

}
